#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_soppafcsymm.info <<'%EOF%'
   rsp_soppafcsymm
   ---------------
   Molecule:         H2O
   Wave Function:    MP2 (SOPPA) / cc-pVDZ
   Test Purpose:     Fermi-contact. Symmetry
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_soppafcsymm.mol <<'%EOF%'
BASIS
cc-pVDZ
SOPPA calculation of Fermi contact contribution to
spin-spin coupling constants. Symmetry
    2    2  X  Z
        8.    1
O     0.0 -0.2249058930 0.0
        1.    1
H     1.45235 0.899623 0.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_soppafcsymm.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONSE
**INTEGRALS
.FC
**WAVE FUNCTION
.HF
.MP2
**RESPONSE
.S0MIX
.TRPFLG
.SOPPA
*LINEAR
.PROPRT
FC O 001
.PROPRT
FC H 002
.PROPRT
FC H 003
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_soppafcsymm.check
cat >>rsp_soppafcsymm.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# Integral setup
#CRIT1=`$GREP "Calculation of one\- and two\-electron Hamiltonian integrals\." $log | wc -l`
#CRIT2=`$GREP "The following one\-electron property integrals are calculated" $log | wc -l`
#CRIT3=`$GREP "\- overlap integrals" $log | wc -l`
#CRIT4=`$GREP "\- Fermi contact integrals" $log | wc -l`
#CRIT5=`$GREP "\(Dirac delta function integrals\)" $log | wc -l`
#CRIT6=`$GREP "two-electron integrals are transformed to P-supermatrix elements" $log | wc -l`
#CRIT7=`$GREP "Integrals for all indirect spin\-spin coupling and/or shielding tensors are calculated\." $log | wc -l`
#TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7`
TEST[1]=7
CTRL[1]=7
ERROR[1]="INTEGRAL CALCULATION NOT SET UP CORRECTLY"

# Basis set
CRIT1=`$GREP "O * 1 * 8\.0000 * 26 * 14 * \[9s4p1d\|3s2p1d\]" $log | wc -l`
CRIT2=`$GREP "H * 2 * 1\.0000 * 7 * 5 * \[4s1p\|2s1p\]" $log | wc -l`
CRIT3=`$GREP "total\: * 3 * 10\.0000 * 40 * 24" $log | wc -l`
CRIT4=`$GREP "Spherical harmonic basis used\." $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[2]=4
ERROR[2]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 9" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (\-0|\-)\.2249058930" $log | wc -l`
CRIT4=`$GREP "3 * z * (0| )\.0000000000" $log | wc -l`
CRIT5=`$GREP "4 * x * 1\.4523500000" $log | wc -l`
CRIT6=`$GREP "5 * y * (0| )\.8996230000" $log | wc -l`
CRIT7=`$GREP "6 * z * (0| )\.0000000000" $log | wc -l`
CRIT8=`$GREP "7 * x * \-1\.4523500000" $log | wc -l`
CRIT9=`$GREP "8 * y * (0| )\.8996230000" $log | wc -l`
CRIT10=`$GREP "9 * z * (0| )\.0000000000" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10`
CTRL[3]=10
ERROR[3]="GEOMETRY NOT READ CORRECTLY"

# Energies
CRIT1=`$GREP "Hartree\-Fock total energy *\: * \-76\.025681483" $log | wc -l`
CRIT2=`$GREP "\= MP2 second order energy *\: * \-76\.2306668" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="ENERGIES NOT CORRECT"

# Fermi-contact contribution
CRIT1=`$GREP "\@.*FC O *001 .* FC O *001 .* 1\.32699.......(D|E)\+04" $log | wc -l`
CRIT2=`$GREP "\@.*FC O *001 .* FC H *002 .* \-8\.5365........(D|E)\+01" $log | wc -l`
CRIT3=`$GREP "\@.*FC H *002 .* FC H *002 .* 1\.08505.......(D|E)\+02" $log | wc -l`
CRIT4=`$GREP "\@.*FC H *003 .* FC H *003 .* 1\.05952.......(D|E)\+02" $log | wc -l`
TEST[5]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[5]=4
ERROR[5]="FERMI-CONTACT NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
